<%@ taglib uri="http://www.springframework.org/security/tags" prefix="sec" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@ taglib uri="/struts-tags" prefix="s"%>

<link rel="stylesheet" href="styles/form-input.css" type="text/css" media="all" />
<link rel="stylesheet" href="styles/displaytag.css" type="text/css" media="all" />
<link type="text/css" rel="stylesheet" href="js/jquery/css/ui-lightness/jquery-ui-1.8.16.custom.css"/>
<script type="text/javascript" src="js/jquery/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
   		$("button").button();
 		});
	
	var formSubmitted=false;  
	function preventDoubleSubmit() {  
	   if(formSubmitted) {  
	      return false;  
	   }  
	   
	   formSubmitted = true;  
	   return true;  
	}	
</script>

<sec:authorize access="hasRole('R_ADMIN')">
	<div class="error-text"><s:actionerror /></div>
	<div class="error-text"><s:fielderror /></div>
	<div class="message-text"><s:actionmessage /></div>
	
	<h3>User Management</h3>
	<div align="center">
		<s:form theme="simple" validate="true" method="POST" >
			<s:hidden name="action"/>
			<fieldset style="width:450px">
            	<legend><h3>User</h3></legend>
            	<div align="left">
            		<table cellpadding="3" class="table-form">
						<tr><td id="td1">Username</td><td>
								<c:choose>
									<c:when test="${action=='E'}">
										<s:textfield name="username" readonly="true" />
									</c:when>
									<c:otherwise><s:textfield name="username" maxlength="30"/>*</c:otherwise>
								</c:choose>
							</td></tr>
						<%--<c:choose>
							<c:when test="${action=='N'}">
								<tr><td>Password</td><td><s:password name="password" maxlength="20"/>*</td></tr>
								<tr><td>Confirm Password</td><td><s:password name="confirmPassword" maxlength="20"/>*</td></tr>
							</c:when>
						</c:choose> --%>
						<tr><td>Email</td><td><s:textfield name="email" maxlength="50"/>*</td></tr>
						<tr><td>Area</td><td><s:select name="areaId" list="areaMap" headerKey="-1" headerValue="Select Area"/></td></tr>
						<tr><td>Group Roles</td><td><s:select name="chosedGroup" list="groupRoles"  listKey="id" listValue="groupName" headerKey="-1" headerValue="Select Role" /></td></tr>
						<tr><td>Aktif</td><td><s:checkbox name="enabled" /></td></tr>
					</table>					
            	</div>
            	<br>
				<s:submit type="button" action="addOrUpdateUser">SUBMIT</s:submit>
				<c:if test="${action=='E'}">
					<button type="button" onclick="window.location.href='listUser'">CANCEL</button>
					<%-- <s:submit type="button" action="resetPassword">RESET PASSWORD</s:submit> --%>
				</c:if>			
			</fieldset>
			<s:token />
		</s:form>
	</div>
	<br>
	<br>
	<div>
		<display:table 	id			= "um"
              			name       	= "${userModels}"
             			pagesize   	= "10" style="width: 800px"
              			requestURI 	= "/listUser" class="display" >
              	              	
   			<display:column title	= "NO."
              				value   = "${um_rowNum}" />
              				   
		   	<display:column title 	= "Username"
		   					nulls	= "false" sortable= "true" >
		   		<c:url var="urlEditUser" value="editUser">
					<c:param name="user" value="${um.username}"/>
				</c:url>
				<a href="${urlEditUser}">${um.username}</a>
		   	</display:column>
		   	
		   	<display:column title 	= "Email"
		   					value	= "${um.email}" 
		   					nulls	= "false" autolink="true" sortable="true"/>
		   	
		   	<display:column title 	= "Area"
		   					value	= "${um.areaName}" 
		   					nulls	= "false" sortable= "true" />
		   	
		   	<display:column title 	= "Roles"
		   					value	= "${um.auth}" 
		   					nulls	= "false" sortable= "true" />
		   	
		   	<display:column title 	= "Aktif"
		   					nulls	= "false" sortable= "true" >
		   		<c:choose>
					<c:when test="${um.enable==true}">
						<img src="js/easyui/themes/icons/ok.png">
					</c:when>
					<c:otherwise><img src="js/easyui/themes/icons/no.png"></c:otherwise>
				</c:choose>
		   	</display:column>
		   					
		   	<display:column title 	= "">
				<c:url var="urlRemoveUser" value="removeUser">
					<c:param name="user" value="${um.username}"/>
				</c:url>
		   		<a href="${urlRemoveUser}" onclick="return confirm('Delete this user?');">[Delete]</a>
		   	</display:column>
		</display:table>
	</div>
</sec:authorize>